﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Management.Instrumentation;
using Microsoft.Win32;
using System.Runtime.InteropServices;

public class Sys_Info
{
    [StructLayout(LayoutKind.Sequential)]
    public struct OSVERSIONINFO
    {
        public int dwOSVersionInfoSize;
        public int dwMajorVersion;
        public int dwMinorVersion;
        public int dwBuildNumber;
        public int dwPlatformId;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
        public string szCSDVersion;
    }
    [DllImport("kernel32.Dll")]
    public static extern short GetVersionEx(ref OSVERSIONINFO o);
    static public string GetServicePack()
    {
        OSVERSIONINFO os = new OSVERSIONINFO();
        os.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFO));
        GetVersionEx(ref os);
        if (os.szCSDVersion == "")
            return "";
        else
            return os.szCSDVersion;
    }

    public static string get_Windows()
    {
        var name = (from x in new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>()
                    select x.GetPropertyValue("Caption")).First();
        return name != null ? name.ToString() : "Unknown";
    }

    public static string get_video()
    {
        ManagementObjectSearcher searcher= new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");

        string graphicsCard = string.Empty;
        foreach (ManagementObject mo in searcher.Get())
        {
            foreach (PropertyData property in mo.Properties)
            {
                if (property.Name == "Description")
                {
                    return property.Value.ToString();
                    break;
                }
            }
        }
        return graphicsCard;
    }

    public static string DX_Version()
    {
        string directxMajorVersion = string.Empty;
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DirectX"))
        {
            string versionStr = key.GetValue("Version") as string;
            if (!string.IsNullOrEmpty(versionStr))
            {
                var versionComponents = versionStr.Split('.');
                if (versionComponents.Length > 1)
                {
                    int directXLevel;
                    if (int.TryParse(versionComponents[1], out directXLevel))
                    {
                        directxMajorVersion = directXLevel.ToString();
                    }
                }
            }
        }
        return directxMajorVersion;
    }
}
